package com.cgt.springboot.interceptor;

import com.cgt.springboot.pojo.Admin;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class LoginInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		//1.判断用户有没有登录
		//2.如果登录了，就放行，可以访问后台的资源
		//3.如果没有登录，跳转到登录界面
		HttpSession session = request.getSession();
		Admin admin = (Admin) session.getAttribute("admin");
//		if (admin == null) {
//			//没有登录，跳转到登录界面
//			response.sendRedirect("/page/login");
//			return false;
//		}

		return true;
	}
}

